﻿// Decompiled with JetBrains decompiler
// Type: MCM.Abstractions.SettingsPresetWrapper`1
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using HarmonyLib.BUTR.Extensions;
using MCM.Abstractions.Base;
using MCM.Common;
using System;

#nullable enable
namespace MCM.Abstractions
{
  public abstract class SettingsPresetWrapper<TSetting> : ISettingsPreset, IWrapper where TSetting : BaseSettings, IWrapper
  {
    private readonly SettingsPresetWrapper<
    #nullable disable
    TSetting>.GetSettingsIdDelegate
    #nullable enable
    ? _methodGetSettingsIdDelegate;
    private readonly SettingsPresetWrapper<
    #nullable disable
    TSetting>.GetIdDelegate
    #nullable enable
    ? _methodGetIdDelegate;
    private readonly SettingsPresetWrapper<
    #nullable disable
    TSetting>.GetNameDelegate
    #nullable enable
    ? _methodGetNameDelegate;
    private readonly SettingsPresetWrapper<
    #nullable disable
    TSetting>.LoadPresetDelegate
    #nullable enable
    ? _methodLoadPresetDelegate;
    private readonly SettingsPresetWrapper<
    #nullable disable
    TSetting>.SavePresetDelegate
    #nullable enable
    ? _methodSavePresetDelegate;

    public string SettingsId
    {
      get
      {
        SettingsPresetWrapper<TSetting>.GetSettingsIdDelegate settingsIdDelegate = this._methodGetSettingsIdDelegate;
        return (settingsIdDelegate != null ? settingsIdDelegate() : (string) null) ?? "ERROR";
      }
    }

    public string Id
    {
      get
      {
        SettingsPresetWrapper<TSetting>.GetIdDelegate methodGetIdDelegate = this._methodGetIdDelegate;
        return (methodGetIdDelegate != null ? methodGetIdDelegate() : (string) null) ?? "ERROR";
      }
    }

    public string Name
    {
      get
      {
        SettingsPresetWrapper<TSetting>.GetNameDelegate methodGetNameDelegate = this._methodGetNameDelegate;
        return (methodGetNameDelegate != null ? methodGetNameDelegate() : (string) null) ?? "ERROR";
      }
    }

    public object? Object { get; }

    protected SettingsPresetWrapper(object? @object)
    {
      if (@object == null)
        return;
      this.Object = @object;
      Type type = @object.GetType();
      this._methodGetSettingsIdDelegate = AccessTools2.GetPropertyGetterDelegate<SettingsPresetWrapper<TSetting>.GetSettingsIdDelegate>(@object, type, nameof (SettingsId));
      this._methodGetIdDelegate = AccessTools2.GetPropertyGetterDelegate<SettingsPresetWrapper<TSetting>.GetIdDelegate>(@object, type, nameof (Id));
      this._methodGetNameDelegate = AccessTools2.GetPropertyGetterDelegate<SettingsPresetWrapper<TSetting>.GetNameDelegate>(@object, type, nameof (Name));
      this._methodLoadPresetDelegate = AccessTools2.GetDelegate<SettingsPresetWrapper<TSetting>.LoadPresetDelegate>(@object, type, "LoadPreset");
      this._methodSavePresetDelegate = AccessTools2.GetDelegate<SettingsPresetWrapper<TSetting>.SavePresetDelegate>(@object, type, "SavePreset");
    }

    protected abstract TSetting Create(object? @object);

    public BaseSettings LoadPreset()
    {
      SettingsPresetWrapper<TSetting>.LoadPresetDelegate loadPresetDelegate = this._methodLoadPresetDelegate;
      return (BaseSettings) this.Create(loadPresetDelegate != null ? loadPresetDelegate() : (object) null);
    }

    public bool SavePreset(BaseSettings settings)
    {
      if (settings is TSetting setting)
      {
        object settings1 = setting.Object;
        if (settings1 != null)
        {
          SettingsPresetWrapper<TSetting>.SavePresetDelegate savePresetDelegate = this._methodSavePresetDelegate;
          return savePresetDelegate != null && savePresetDelegate(settings1);
        }
      }
      return false;
    }

    private delegate string GetSettingsIdDelegate() where TSetting : 
    #nullable disable
    BaseSettings, IWrapper;

    private delegate 
    #nullable enable
    string GetIdDelegate() where TSetting : 
    #nullable disable
    BaseSettings, IWrapper;

    private delegate 
    #nullable enable
    string GetNameDelegate() where TSetting : 
    #nullable disable
    BaseSettings, IWrapper;

    private delegate 
    #nullable enable
    object LoadPresetDelegate() where TSetting : 
    #nullable disable
    BaseSettings, IWrapper;

    private delegate bool SavePresetDelegate(
    #nullable enable
    object settings) where TSetting : 
    #nullable disable
    BaseSettings, IWrapper;
  }
}
